package com.example.contentprovider;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;

import androidx.annotation.Nullable;

public class Student extends SQLiteOpenHelper {
    public Student(@Nullable Context context,
                   @Nullable String name,
                   @Nullable SQLiteDatabase.CursorFactory factory,
                   int version) {
        super(context, name, factory, version);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("create table usergrade("
                + "_id integer primary key autoincrement,"
                + "name text,"
                + "company text not null,"
                + "job text not null)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

    public Cursor queryAll(String tableName){
        return getWritableDatabase()
                .query(tableName,null,null,
                        null,null,null,null);

    }

    public Uri insertData(String tableName, ContentValues values){

        long id = getWritableDatabase().insert(tableName,null,values);

        if (id>0){
            return Uri.parse(
                    "content://com.imti.contentprovider/stu/job" + id);
        }else {
            return null;
        }
    }
}
